<?php

namespace App\Repository\Anchor;

use App\Models\Anchor\AnchorAuthorModel as model;
use App\Repository\BaseRepository;

//达人
class AnchorAuthorRepository extends BaseRepository
{
    public $model;
    public $log;

    public function __construct()
    {
        $this->model = new model();
//    $this->log = new Logger('anchor');
//    $this->log->pushHandler(
//      (new RotatingFileHandler(storage_path('/logs/anchor.log'), 14, Logger::DEBUG, true, 0777))->setFormatter(new LineFormatter(null, null, true, true))
//    );
        parent::__construct();
    }

    //列表
    public function index($where, $page = 1, $limit = 10)
    {
        $pk = $this->model->getKeyName();
//        先要总数
        $totalRows = $this->model->count($pk);
//        再加上分页查询
        $rows = $this->model->page($page, $limit)->with(["anchor" => function ($query) {
            $query->select(['id', 'nickname']);
        }])->searchWhere($where)->get();
//        print_r($this->getLastSql(true));
//        print_r($rows->toArray());
        return $this->returnMsg(200, '查询成功', $rows, $totalRows);
    }
}
